

#ifndef __UART_H
#define __UART_H

#include "include.h"
#include "bluetooth.h"

#define UART_BAUD_115200 0x01a0
#define UART_BAUD_921600 0x00c0

#define USART_HardwareFlowControl_None      	(0<<4)
#define USART_HardwareFlowControl_ENABLE       (1<<4)

#define USART_Mode_Single_Line        (1<<6)
#define USART_Mode_duplex                      (0<<6)

#define USART_Parity_Even                    (0<<1)
#define USART_Parity_Odd                     (1 << 1)

#define USART_StopBits_1                 (0<<3)
#define USART_StopBits_2                 (1<<3)

#define USART_WordLength_8b                  (0<<2)
#define USART_WordLength_9b                  (1<<2)

#define RECEIVE_HEAD		1
#define RECEIVE_LENGTH		2
#define RECEIVE_TYPE			3

#define UART_RSADDR 0x1c00
#define UART_RxLen 0x1ff
#define UART_TSADDR 0x1e00
#define UART_TxLen 0x1ff

/*******************Event Type*********************/
#define 	EVEVT_START_CONNECT 		1	
#define	EVENT_DISCONNECT			2
#define	EVENT_RECV_DATA 			3


/**
    * @brief Initializes the structure of uart parameters
    */
typedef struct{
	u16_t USART_BaudRate;   /*!< UART baud rate divisor by uart clock*/      
	u16_t USART_WordLength;/*!< UART Data length 1: 9 bits; 0: 8 bits*/ 
  	u16_t USART_StopBits;       /*!< */   
  	u16_t USART_Parity;       /*!< 1: odd parity; 0: even parity*/     
  	u16_t USART_Mode; 	/*!< 1: enable half duplex single line UART;0:enable duplex line UART*/ 
  	u16_t USART_HardwareFlowControl; /*!< 1: enable RTS/CTS flow control;0:disable RTS/CTS flow control*/ 
  	u16_t USART_TXLen; /*!< UART Tx DMA buffer size*/ 
  	u16_t USART_RXLen;/*!< UART Rx DMA buffer size*/ 
  	u16_t USART_TXaddr;/*!< UART TX DMA start address pointer*/ 
  	u16_t USART_RXaddr;	/*!< UART RX DMA start address pointer*/ 
}UartInitRegDef;

/**
  * @brief Uart initization
  * @param Def_struct : Contains all the information needed for uart initialization
  * @return null
  */
 void UART_Init(UartInitRegDef* Def_struct);
 
 /**
  * @brief Read date from uart 
  * @param pbuff : the pointer where the data stored 
  * @param len : number of bytes read from uart
  * @return The number of bytes read
  */
 u16_t UART_ReciveData(u8_t* pbuff, u16_t len);
 
 /**
  * @brief Write data to uart
  * @param pbuff : pointer where data is send to  
  * @param len :  number of bytes sending data
  * @return null
  */
 void UART_SendData(u8_t* pbuff, u16_t len);
 
 /**
  * @brief Send event by uart
  * @param EventType : start connect , disconnect, recvice data
  * @return null
  */
 void Uart_SendEvent(u8_t* EventType);
 
 /**
  * @brief printf log by uart
  * @param string_ptr : print content information
  * @param len : data len
  * @return null
  */
void printf(u8_t *string_ptr,u16_t len);

#endif
